package com.augrain.microframework.web.sensitive;

import java.util.function.Function;

/**
 * 对需要特别脱敏的字段指定脱敏规则
 **/
public enum SensitiveStrategy {
    /**
     * 对身份证进行脱敏
     */
    ID_CARD(s -> s.replaceAll("(\\d{4})\\d{10}(\\w{4})", "$1****$2")),

    /**
     * 对电话号码进行脱敏
     */
    PHONE(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),

    /**
     * 对密码进行脱敏，全部加密即可
     */
    PASSWORD(s -> "********");

    private final Function<String, String> desensitizeSerializer;

    SensitiveStrategy(Function<String, String> desensitizeSerializer) {
        this.desensitizeSerializer = desensitizeSerializer;
    }

    // 用于后续获取脱敏的规则，实现脱敏
    public Function<String, String> desensitizeSerializer() {
        return desensitizeSerializer;
    }


}